package com.xingshentech.ugv.operate.base;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;

import com.google.android.material.snackbar.Snackbar;

import androidx.annotation.LayoutRes;
import androidx.appcompat.app.AppCompatActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.xingshentech.ugv.operate.R;
import com.xingshentech.ugv.operate.module.utils.ToastUtil;

public abstract class BaseActivity extends AppCompatActivity {

    public Activity mInstance;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        mInstance = this;
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // “横屏”模式
        super.onCreate(savedInstanceState);
        AppManager.getAppManager().addActivity(this);
        setStatusBar();
        initVariable();          // 跳转activity  获取数据
        setContentView(getLayoutResId());    //初始化布局
        ButterKnife.bind(this);
        initView(savedInstanceState);     //view的触发事件
        initData();                   //加载数据
    }


    protected abstract @LayoutRes
    int getLayoutResId();

    protected void initVariable() {

    }

    protected void initView(Bundle savedInstanceState) {

    }
    protected void initData() {

    }
    protected void setStatusBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);//实现状态栏文字颜色为暗色
        }
    }

    public void toast(String str) {
        ToastUtil.showToast(str);
    }
    public void toast(int id) {
        ToastUtil.showToast(id);
    }
    public void toast(CharSequence s) {
        ToastUtil.showToast(s.toString());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        AppManager.getAppManager().finishActivity(this);
    }

    public View EmptyView() {
        return EmptyView("");
    }


    public View EmptyView(String msg) {
//        View view = LayoutInflater.from(getBaseActivity()).inflate(R.layout.empty_view, recyclerView, false);
        View view = LayoutInflater.from(this).inflate(R.layout.empty_view, null);
        if (msg != null && !"".equals(msg)) {
            TextView tvMsg = view.findViewById(R.id.tv_msg);
            tvMsg.setText(msg);
        }
        return view;
    }

}